package com.zm.demo.core.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * 子数组的最小值之和
 * @author zoum
 * @create 2020/1/13 13:40
 */
public class SumSubarrayMins {

    public static int sumSubarrayMins(int[] A) {

        if (A == null){
            return 0;
        }

        Double sum = 0D;

        int[][]dp = new int[A.length][A.length];
        for (int i = 0; i <A.length; i++) {
            for (int j = i; j <A.length; j++) {
                if (j==i){
                    dp[i][j] = A[j];
                }else {
                    dp[i][j] = Math.min(A[j],dp[i][j-1]);
                }
                sum+=(dp[i][j]);
            }
        }

        return Double.valueOf(sum%(Math.pow(10,9)+7)).intValue();
    }

    public static void main(String[]args){
        sumSubarrayMins(new int[]{3,1,2,4});
    }



}
